#include<stdio.h>

#define MAXSIZE 12500

typedef struct  
{
	int i,j;
	int e;
}Triple;

typedef struct
{
	Triple data[MAXSIZE+1];
	int rpos[MAXSIZE];
	int mu,nu,tu;
}RLSMatrix;

int MultSMatrix(RLSMatrix M,RLSMatrix N,RLSMatrix &Q)
{
	int ctemp[MAXSIZE];
	int arow,tp,p,brow,t,q,ccol;
	if (M.nu!=N.mu)
	{
		return 0;
	}
	Q.mu=M.mu;
	Q.nu=N.nu;
	Q.tu=0;
	if (M.tu*N.tu!=0)
	{
		for (arow=1;arow<=M.mu;++arow)
		{
			ctemp[arow]=0;
			Q.rpos[arow]=Q.tu+1;
			if (arow<M.mu)
			{
				tp=M.rpos[arow+1];
			} 
			else
			{
				tp=M.tu+1;
			}
			for (p=M.rpos[arow];p<tp;++p)
			{
				brow=M.data[p].j;
				if (brow<N.mu)
				{
					t=N.rpos[brow+1];
				} 
				else
				{
					t=N.tu+1;
				}
				for (q=N.rpos[brow];q<t;++q)
				{
					ccol=N.data[q].j;
					ctemp[ccol]=N.data[p].e*N.data[q].e;
				}
			}
			for (ccol=1;ccol<=Q.nu;++ccol)
			{
				if (ctemp[ccol])
				{
					if (++Q.tu>MAXSIZE)
					{
						return 0;
					}
					Q.data[Q.tu].i=arow;
					Q.data[Q.tu].j=ccol;
					Q.data[Q.tu].e=ctemp[ccol];
				}
			}
		}
	}
	return 1;
}


void main()
{
}

      